//
//  HCNavigationBar.m
//  Painter
//
//  Created by qinyulun on 15/6/22.
//  Copyright (c) 2015年 贵州蜂巢科技发展有限责任有限公司. All rights reserved.
//

#import "HCNavigationBar.h"
#import "XHLMacroDefin.h"

NSInteger const bNavigationBar_LeftTag  = 101;
NSInteger const bNavigationBar_RightTag = 102 ;
NSInteger const bNavigationBar_RightTwoTag = 103 ;
NSInteger const SPACE = 8 ;

@implementation HCNavigationBar

//自定义左边按钮
+ (void)setNavigationBarLeftButton:(UIViewController *)viewController withBtnNormalImg:(UIImage *)normalImage withBtnPresImg:(UIImage *)pressImage withTitle:(NSString *)title withAction:(SEL)action
{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    leftBtn.frame = CGRectMake(0, 0,normalImage.size.width, normalImage.size.height);
    [leftBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:pressImage forState:UIControlStateHighlighted];
    [leftBtn addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setTitle:title forState:UIControlStateNormal];
    leftBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    leftBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
    leftBtn.tag = bNavigationBar_LeftTag;
    if (IOS7) {
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,6,0,0)];
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 300);
    UIBarButtonItem* left =  [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -10;
        [viewController.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,left,nil]];
        
    } else {
        viewController.navigationItem.leftBarButtonItem =  left;
    }
    
    
}

//自定义右边按钮
+ (void)setNavigationBarRightButton:(UIViewController *)viewController withBtnNormalImg:(UIImage *)normalImage withBtnPresImg:(UIImage *)pressImage withTitle:(NSString *)title withAction:(SEL)action
{
    UIButton *rightBtn = [[UIButton alloc] init] ;
    
    if (normalImage) {
        rightBtn.frame = CGRectMake(0, 0,normalImage.size.width, normalImage.size.height);
    }else{
        rightBtn.frame = CGRectMake(0, 0, 40, 30);
    }
    
    [rightBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:pressImage forState:UIControlStateHighlighted];
    [rightBtn addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:title forState:UIControlStateNormal];
    rightBtn.titleLabel.textAlignment = 1;
    rightBtn.tag = bNavigationBar_RightTag;
    if (title.length >= 4) {
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        rightBtn.frame = CGRectMake(0, 0, 65 , 30);
        
    }else{
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    rightBtn.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
    rightBtn.backgroundColor = [UIColor clearColor];
    rightBtn.tag = bNavigationBar_RightTag ;
    
    //    if (IOS7) {
    //        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
    //        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
    //        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    //    }
    
    UIBarButtonItem* right =  [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -10;
        [viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,right,nil]];
        
    } else {
        viewController.navigationItem.rightBarButtonItem =  right;
    }
}

// 自定义左边的按钮加上禁用的图片显示
+ (void)setNavigationBarLeftButton:(UIViewController *)viewController withBtnNormalImg:(UIImage *)normalImage withBtnPresImg:(UIImage *)pressImage withBtnEnableImg:(UIImage *)enableImg withTitle:(NSString *)title withAction:(SEL)action
{
    
    UIButton *leftBtn = [[UIButton alloc] init] ;
    leftBtn.frame = CGRectMake(0, 0,normalImage.size.width, normalImage.size.height);
    [leftBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:pressImage forState:UIControlStateHighlighted];
    [leftBtn setBackgroundImage:enableImg forState:UIControlStateDisabled];
    [leftBtn addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setTitle:title forState:UIControlStateNormal];
    leftBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    leftBtn.titleLabel.shadowColor = [UIColor blackColor];
    leftBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
    if (IOS7) {
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [leftBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,6,0,0)];
    
    UIBarButtonItem* left =  [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -10;
        [viewController.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,left,nil]];
        
    } else {
        viewController.navigationItem.leftBarButtonItem = left;
    }
}

//自定义右边带禁用图片的按钮
+ (void)setNavigationBarRightButton:(UIViewController *)viewController withBtnNormalImg:(UIImage *)normalImage withBtnPresImg:(UIImage *)pressImage withEnabledImage:(UIImage *)enabledImage withTitle:(NSString *) title withAction:(SEL)action
{
    UIButton *rightBtn = [[UIButton alloc] init] ;
    NSInteger width = 0;
    NSInteger height = 0 ;
    if (!normalImage) {
        width = widthForString(title,kFontHeitiRegular_20,NavBarHight);
        height = NavBarHight ;
    }else{
        width = normalImage.size.width;
        height = normalImage.size.height ;
    }
    rightBtn.frame = CGRectMake(0, 0,width, height);
    [rightBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:pressImage forState:UIControlStateHighlighted];
    [rightBtn setBackgroundImage:enabledImage forState:UIControlStateDisabled];
    [rightBtn addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:title forState:UIControlStateNormal];
    [rightBtn setTitle:title forState:UIControlStateHighlighted];
    rightBtn.titleLabel.textAlignment = 1;
    rightBtn.tag = bNavigationBar_RightTag;
    if (title.length >= 4) {
        rightBtn.titleLabel.font = kFontHeitiRegular_16;
        
    }else{
        rightBtn.titleLabel.font = kFontHeitiRegular_18;
    }
    rightBtn.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    if (IOS7) {
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    
    UIBarButtonItem* right =  [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    right.enabled = NO;
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -10;
        [viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,right,nil]];
        
    } else {
        viewController.navigationItem.rightBarButtonItem =  right;
    }

}


//自定义右边带禁用图片的按钮,字体居中
+ (void)setNavigationBarRightButtonTitleCenter:(UIViewController *)viewController withBtnNormalImg:(UIImage *)normalImage withBtnPresImg:(UIImage *)pressImage withEnabledImage:(UIImage *)enabledImage withTitle:(NSString *) title withAction:(SEL)action
{
    UIButton *rightBtn = [[UIButton alloc] init] ;
    rightBtn.frame = CGRectMake(0, 0,normalImage.size.width, normalImage.size.height);
    [rightBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:pressImage forState:UIControlStateHighlighted];
    [rightBtn setBackgroundImage:enabledImage forState:UIControlStateDisabled];
    [rightBtn addTarget:viewController action:action forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:title forState:UIControlStateNormal];
    rightBtn.titleLabel.textAlignment = 1;
    if (title.length >= 4) {
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }else{
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    rightBtn.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
    rightBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
    
    if (IOS7) {
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [rightBtn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    
    UIBarButtonItem* right =  [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    right.enabled = NO;
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -10;
        [viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,right,nil]];
        
    } else {
        viewController.navigationItem.rightBarButtonItem =  right;
    }
}

//自定义右边带禁用图片的按钮
+ (void)setNavigationBarRightView:(UIViewController *)viewController
              withBtnNormalImgOne:(UIImage *)normalImage1
                withBtnPresImgOne:(UIImage *)pressImage1
              withBtnNormalImgTwo:(UIImage *)normalImage2
                withBtnPresImgTwo:(UIImage *)pressImage2
                     withTitleOne:(NSString *) title1
                     withTitleTwo:(NSString *)title2
                    withActionOne:(SEL)action1
{
    //    int width = normalImage1.size.width + normalImage2.size.width + Navigation_Bar_Right_View_Space;
    int width = normalImage1.size.width + normalImage2.size.width-8 ;
    int height1 = normalImage1.size.height ;
    int height2 = normalImage2.size.height ;
    int height = height2>height1?height2:height1;
    UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    view.backgroundColor = [UIColor clearColor];
    view.userInteractionEnabled = YES ;
    
    UIButton *rightBtn1 = [UIButton buttonWithType:UIButtonTypeCustom] ;
    rightBtn1.userInteractionEnabled = YES;
    rightBtn1.tag =bNavigationBar_RightTag;
    rightBtn1.frame = CGRectMake(0, 0,normalImage1.size.width, normalImage1.size.height);
    [rightBtn1 setBackgroundImage:normalImage1 forState:UIControlStateNormal];
    [rightBtn1 setBackgroundImage:pressImage1 forState:UIControlStateHighlighted];
    [rightBtn1 addTarget:viewController action:action1 forControlEvents:UIControlEventTouchUpInside];
    [rightBtn1 setTitle:title1 forState:UIControlStateNormal];
    rightBtn1.titleLabel.textAlignment = 1;
    
    
    if ([title1 isEqualToString:@"取消关注"]) {
        rightBtn1.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }else{
        rightBtn1.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    rightBtn1.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn1.titleLabel.shadowOffset = CGSizeMake(0, 1);
    [view addSubview:rightBtn1];
    
    UIButton *rightBtn2 = [[UIButton alloc] init] ;
    rightBtn2.tag = bNavigationBar_RightTwoTag;
    rightBtn2.frame = CGRectMake(CGRectGetMaxX(rightBtn1.frame), 0,normalImage2.size.width, normalImage2.size.height);
    [rightBtn2 setBackgroundImage:normalImage2 forState:UIControlStateNormal];
    [rightBtn2 setBackgroundImage:pressImage2 forState:UIControlStateHighlighted];
    [rightBtn2 addTarget:viewController action:action1 forControlEvents:UIControlEventTouchUpInside];
    [rightBtn2 setTitle:title2 forState:UIControlStateNormal];
    rightBtn2.titleLabel.textAlignment = 1;
    if ([title1 isEqualToString:@"取消关注"]) {
        rightBtn2.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }else{
        rightBtn2.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    rightBtn2.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn2.titleLabel.shadowOffset = CGSizeMake(0, 1);
    [view addSubview:rightBtn2];
    
    UIBarButtonItem* right =  [[UIBarButtonItem alloc] initWithCustomView:view];
    //end
    if (IOS7) {
        UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        spaceButtonItem.width = -SPACE;
        [viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:spaceButtonItem,right,nil]];
        
    } else {
        viewController.navigationItem.rightBarButtonItem =  right;
    }
    //    rightBtn1.backgroundColor = [UIColor purpleColor];
    //    rightBtn2.backgroundColor = [UIColor yellowColor];
    //    [rightBtn1 setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];//上 左 下 右
}


//自定义右边按钮(两个按钮)
+ (void)setNavigationBarRightButtons:(UIViewController *)viewController
                 withBtnNormalImgOne:(UIImage *)normalImage1
                   withBtnPresImgOne:(UIImage *)pressImage1
                 withBtnNormalImgTwo:(UIImage *)normalImage2
                   withBtnPresImgTwo:(UIImage *)pressImage2
                        withTitleOne:(NSString *) title1
                        withTitleTwo:(NSString *)title2
                       withActionOne:(SEL)action1
                       withActionTwo:(SEL)action2
{
    
    UIButton *rightBtn1 = [[UIButton alloc] init] ;
    rightBtn1.tag =bNavigationBar_RightTag;
    rightBtn1.frame = CGRectMake(0, 0,normalImage1.size.width, normalImage1.size.height);
    [rightBtn1 setBackgroundImage:normalImage1 forState:UIControlStateNormal];
    [rightBtn1 setBackgroundImage:pressImage1 forState:UIControlStateHighlighted];
    [rightBtn1 addTarget:viewController action:action1 forControlEvents:UIControlEventTouchUpInside];
    [rightBtn1 setTitle:title1 forState:UIControlStateNormal];
    rightBtn1.titleLabel.textAlignment = 1;
    if ([title1 isEqualToString:@"取消关注"]) {
        rightBtn1.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }else{
        rightBtn1.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    rightBtn1.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn1.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    if (IOS7) {
        [rightBtn1 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [rightBtn1 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [rightBtn1 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    
    UIImage *backLine = [UIImage imageNamed:@"common_navi_line"];
    UIImageView *backgroundLine = [[UIImageView alloc] initWithImage:backLine];
    backgroundLine.frame = CGRectMake(rightBtn1.frame.origin.x - 10, -5, backgroundLine.frame.size.width, backgroundLine.frame.size.height);
    [rightBtn1 addSubview:backgroundLine];
    
    UIBarButtonItem* right1 =  [[UIBarButtonItem alloc] initWithCustomView:rightBtn1];
    
    UIButton *rightBtn2 = [[UIButton alloc] init] ;
    rightBtn2.tag = bNavigationBar_RightTwoTag;
    rightBtn2.frame = CGRectMake(0, 0,normalImage2.size.width, normalImage2.size.height);
    [rightBtn2 setBackgroundImage:normalImage2 forState:UIControlStateNormal];
    [rightBtn2 setBackgroundImage:pressImage2 forState:UIControlStateHighlighted];
    [rightBtn2 addTarget:viewController action:action2 forControlEvents:UIControlEventTouchUpInside];
    [rightBtn2 setTitle:title2 forState:UIControlStateNormal];
    rightBtn2.titleLabel.textAlignment = 1;
    if ([title1 isEqualToString:@"取消关注"]) {
        rightBtn2.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }else{
        rightBtn2.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    rightBtn2.titleLabel.shadowColor = [UIColor grayColor];
    rightBtn2.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    if (IOS7) {
        [rightBtn2 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
        [rightBtn2 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateDisabled];
        [rightBtn2 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    }
    
    UIImageView *backgroundLine2 = [[UIImageView alloc] initWithImage:backLine];
    backgroundLine2.frame = CGRectMake(rightBtn1.frame.origin.x - 10, -5, backgroundLine.frame.size.width, backgroundLine.frame.size.height);
    [rightBtn2 addSubview:backgroundLine2];
    
    UIBarButtonItem* right2 =  [[UIBarButtonItem alloc] initWithCustomView:rightBtn2];
    
    
    UIView *view1= [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 10)];
   	UIBarButtonItem* right3 = [[UIBarButtonItem alloc]initWithCustomView:view1];
    
    if (!IOS4) {
        viewController.navigationItem.rightBarButtonItems =[NSArray arrayWithObjects:right1, right3, right2, nil];
    } else {
        
        UIView *rightViewIos4 = [[UIView alloc] initWithFrame:CGRectMake(0, 7, 70, 30)];
        rightViewIos4.userInteractionEnabled = YES;
        rightViewIos4.backgroundColor = [UIColor clearColor];
        [rightViewIos4 addSubview:rightBtn1];
        [rightViewIos4 addSubview:view1];
        [rightViewIos4 addSubview:rightBtn2];
        rightBtn2.frame = CGRectMake(0, 2, rightBtn2.frame.size.width, rightBtn2.frame.size.height);
        view1.frame = CGRectMake(rightBtn2.frame.origin.x + rightBtn2.frame.size.width + 5, view1.frame.origin.y, view1.frame.size.width, view1.frame.size.height);
        
        rightBtn1.frame = CGRectMake(view1.frame.origin.x + view1.frame.size.width + 1, 2, rightBtn1.frame.size.width, rightBtn1.frame.size.height);
        
        UIBarButtonItem* ios4RightBar = [[UIBarButtonItem alloc]initWithCustomView:rightViewIos4];
        viewController.navigationItem.rightBarButtonItem = ios4RightBar;
        
        
    }
    
}


+(void) setNavigationTitle:(UIViewController *) viewController
                 withTitle:(NSString *) title
{
    [[viewController navigationItem] setTitle:title];
    UIFont *font = [UIFont boldSystemFontOfSize:17.0f];
    
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:17.0f]};
    CGSize size = [title sizeWithAttributes:attributes];
    CGRect labelrect = CGRectMake((320 - size.width)/2.0f, (viewController.navigationController.navigationBar.frame.size.height - size.height)/2.0f, size.width, size.height);
    UILabel *label = [[UILabel alloc] initWithFrame:labelrect];
    label.backgroundColor = [UIColor clearColor];
    label.text = title;
    label.font = font;
    label.textColor = [UIColor whiteColor];
    label.shadowOffset = CGSizeMake(0, 1);
    label.textAlignment = NSTextAlignmentCenter;
    viewController.navigationItem.titleView = label;
    
}

+(void) setNavigationTitle:(UIViewController *) viewController
                 withTitleviews:(UIImage*) image
{
    CGSize size = image.size ;
    UIImageView* imageview = [[UIImageView alloc] initWithImage:image];
    imageview.frame = CGRectMake(0, 0, size.width, size.height);
    
    viewController.navigationItem.titleView = imageview ;
    
    
}

+(void) setNavigationTitle:(UIViewController *)viewController withTitle:(NSString *)title titleShadowStyle:(NavBarTitleShadowStyle)titleShadowStyle {
    CGSize shadowOffset = CGSizeZero;
    UIColor *shadowColor = [UIColor clearColor];
    switch (titleShadowStyle) {
        case NavBarTitleShadowStyleDefault:
            shadowOffset = CGSizeMake(0.5, 0.5);
            shadowColor = [UIColor blackColor];
            break;
        default:
            break;
    }
    [HCNavigationBar setNavigationTitle:viewController withTitle:title shadowOffsest:shadowOffset shadowColor:shadowColor];
}

+(void) setNavigationTitle:(UIViewController *) viewController withTitle:(NSString *) title shadowOffsest:(CGSize)shadowOffset shadowColor:(UIColor *)shadowColor
{
    [[viewController navigationItem] setTitle:title];
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:17.0f]};
    CGSize size = [title sizeWithAttributes:attributes];
    CGRect labelrect = CGRectMake((320 - size.width)/2.0f, (viewController.navigationController.navigationBar.frame.size.height - size.height)/2.0f, size.width, size.height);
    UILabel *label = [[UILabel alloc] initWithFrame:labelrect];
    label.backgroundColor = [UIColor clearColor];
    label.text = title;
    label.font = [UIFont systemFontOfSize:17.0f];
    label.textColor = [UIColor whiteColor];
    label.shadowOffset = shadowOffset;
    label.shadowColor = shadowColor;
    label.textAlignment =NSTextAlignmentCenter;
    viewController.navigationItem.titleView = label;
    
}


@end
